package it.polimi.entities;

import it.polimi.entitiesDTO.FlightDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the flight database table.
 * 
 */
@Entity
@NamedQueries ({ @NamedQuery(name=Flight.FIND_ALL, query="SELECT f FROM Flight f"),
				 @NamedQuery(name=Flight.FIND_FLIGHT, query="SELECT f FROM Flight f WHERE f.id = :id"),
				 @NamedQuery(name=Flight.FIND_FLIGHT_BY_DEPARTURE, query="SELECT f FROM Flight f WHERE f.airport1.name = :airport1"),
				 @NamedQuery(name=Flight.FIND_FLIGHT_BY_ARRIVAL, query="SELECT f FROM Flight f WHERE f.airport2.name = :airport2")
})

public class Flight implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Flight.findAll";
	
	public static final String FIND_FLIGHT = "Flight.findFlight";
	
	public static final String FIND_FLIGHT_BY_ARRIVAL ="Flight.findFlightByArrival";
	
	public static final String FIND_FLIGHT_BY_DEPARTURE ="Flight.findFlightByDeparture";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(name="class")
	private String class_;

	private int price;

	private int spots;

	private boolean visibility;

	//bi-directional many-to-one association to Airport
	@ManyToOne
	@JoinColumn(name="departure_airport")
	private Airport airport1;

	//bi-directional many-to-one association to Airport
	@ManyToOne
	@JoinColumn(name="arrival_airport")
	private Airport airport2;


	public Flight() {
		super();
	}
	
	public Flight(FlightDTO flight, Airport departureAirport, Airport arrivalAirport){
		this.airport1 = departureAirport;
		this.airport2 = arrivalAirport;
		this.class_ = flight.getClass_();
		this.price = flight.getPrice();
		this.spots = flight.getSpots();
		this.visibility = flight.isVisibility();
		this.id = flight.getID();
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getClass_() {
		return this.class_;
	}

	public void setClass_(String class_) {
		this.class_ = class_;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getSpots() {
		return this.spots;
	}

	public void setSpots(int spots) {
		this.spots = spots;
	}

	public boolean getVisibility() {
		return this.visibility;
	}

	public void setVisibility(boolean visibility) {
		this.visibility = visibility;
	}

	public Airport getAirport1() {
		return this.airport1;
	}

	public void setAirport1(Airport airport1) {
		this.airport1 = airport1;
	}

	public Airport getAirport2() {
		return this.airport2;
	}

	public void setAirport2(Airport airport2) {
		this.airport2 = airport2;
	}
	
	public String toString(){
		return "ID: " +this.getId() + " From "+ this.getAirport1().getName() + " To"+ this.getAirport2().getName() + " class " + this.getClass_() +" Spots: "+ this.getSpots()+ " Price " + this.getPrice();
	}
		
}